import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter_mall/components/Swipers.dart';
import 'package:flutter_mall/components/GridGood.dart';
import 'package:flutter_mall/components/GridNav.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> with AutomaticKeepAliveClientMixin {

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    // TODO: implement initState
    print("home");
    super.initState();
  }
  final List imgs = [
    "http://hbimg.b0.upaiyun.com/a3e592c653ea46adfe1809e35cd7bc58508a6cb94307-aaO54C_fw658",
    "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2259614868,961155351&fm=26&gp=0.jpg"
  ];
  final List navList = ["nav1","nav2","nav3","nav4","nav5","nav6"];
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context,width: 750,height: 1334);

    return Scaffold(
      // appBar: AppBar(
      //   title: Text("首页"),
      // ),
      body: CustomScrollView(
        //shrinkWrap:true,
        // new Swipers(imgs:imgs),
        slivers: <Widget>[
          //new Swipers(imgs:imgs),
          SliverAppBar(
            title: Text("首页"),
            // floating: true,
            // snap: true,
            pinned: true,  //是否吸顶
            automaticallyImplyLeading:true,
            expandedHeight: 250.0,
            flexibleSpace: FlexibleSpaceBar(
              // title: Text('Demo'),
              // background: Image.network(
              //   imgs[0], fit: BoxFit.cover,),
              background: new Swipers(imgs:imgs),
            ),
          ),
          new GridNav(list:navList),
          new SmallTitle(name:"热门推荐"),
          new GridGood(list:navList),
        ],
      )
    );
  }
}

/**
 * 小标题
 */
class SmallTitle extends StatelessWidget {
  SmallTitle({Key key,this.name}) : super(key:key);
  final String name;
  @override
  Widget build(BuildContext context) {
    return SliverFixedExtentList(
      delegate: new SliverChildBuilderDelegate(
        (BuildContext context,int index) {
          return Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Container(
                padding: EdgeInsets.only(left:ScreenUtil().setWidth(30)),
                child: Text(name,textAlign: TextAlign.left,style:TextStyle(
                  fontSize: ScreenUtil().setWidth(30)
                )),
              )
            ],
          );
        },
        childCount: 1
      ), 
      itemExtent: ScreenUtil().setWidth(100)
    );
  }
}